package com.imast.android.bys.adapter;

import java.util.List;

import com.imast.android.bys.R;
import com.imast.android.bys.io.model.DrawerItem;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DrawerItemAdapter extends BaseAdapter {

	private Context context;
	private List<DrawerItem> items;
	
	public DrawerItemAdapter(Context context, List<DrawerItem> items) {
		this.context = context;
		this.items = items;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		if (convertView == null){
			holder = new ViewHolder();
			
			convertView = inflater.inflate(R.layout.drawer_list_item, null);
			holder.txtTitulo = (TextView)convertView.findViewById(R.id.title_item);
			holder.icono = (ImageView)convertView.findViewById(R.id.icon);
			
			
			convertView.setTag(holder);
			
		} else {
			holder = (ViewHolder)convertView.getTag();
		}
		
		DrawerItem item = items.get(position);
		
		holder.txtTitulo.setText(item.getTitulo());
		holder.icono.setImageResource(item.getIcono());
		
		return convertView;
	}
	
	public static class ViewHolder {
		TextView txtTitulo;
		ImageView icono;
	}

}
